<script setup lang="ts">
import DoctorCard from './doctor-card.vue'
// import { useWindowWidth } from '@/composable/index'
import { useWindowSize } from '@vueuse/core'
import { homePageDoc } from '@/api/home'
import type { homePageDocApiRowsItem } from '@/types/home'
import { ref } from 'vue'
// const { width } = useWindowWidth()
const { width } = useWindowSize()
/*
使用@vueuse/core
1: 下载
2：导入
3：调用（解构出相应的数据）

医生列表
1:定义api
2:导入与调用
3：定义数据类型
4：存储数据并渲染
*/
const list = ref<homePageDocApiRowsItem[]>([])
const getData = async () => {
  const res = await homePageDoc({
    current: 1,
    pageSize: 5
  })
  list.value = res.data.rows
  console.log(res)
}
getData()
</script>

<template>
  <div class="follow-doctor">
    <div className="head">
      <p>推荐关注</p>
      <a href="javascript:;"> 查看更多<i class="van-icon van-icon-arrow" /></a>
    </div>
    <div class="body">
      <!-- swipe 组件 -->
      <van-swipe :loop="false" :show-indicators="false" :width="(150 / 375) * width">
        <van-swipe-item v-for="item in list" :key="item.id">
          <DoctorCard :item="item"></DoctorCard>
        </van-swipe-item>
      </van-swipe>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.follow-doctor {
  background-color: var(--cp-bg);
  height: 250px;
  .head {
    display: flex;
    justify-content: space-between;
    height: 45px;
    align-items: center;
    padding: 0 15px;
    font-size: 13px;
    > a {
      color: var(--cp-tip);
    }
  }
  .body {
    width: 100%;
    overflow: scroll;
  }
}
</style>
